home *** CD-ROM | disk | FTP | other *** search
- /*--------------------------------------------------------------------------*/
- /* */
- /* */
- /* ------------ Bit-Bucket Software <no-Inc> */
- /* \ 10001101 / Writers and Distributors of */
- /* \ 011110 / No-Cost<no-tm> Software. */
- /* \ 1011 / */
- /* ------ */
- /* */
- /* Copyright (C) 1987, 1988, 1989 by Robert Hartman and Vincent Perriello */
- /* */
- /* */
- /* This module was written by Vince Perriello */
- /* with code from several authors */
- /* */
- /* */
- /* Miscellaneous routines used by BinkleyTerm */
- /* */
- /* */
- /* For complete details of the licensing restrictions, please refer */
- /* to the License agreement, which is published in its entirety in */
- /* the MAKEFILE and BT.C, and also contained in the file LICENSE.210. */
- /* */
- /* USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE */
- /* BINKLEYTERM LICENSING AGREEMENT. IF YOU DO NOT FIND THE TEXT OF */
- /* THIS AGREEMENT IN ANY OF THE AFOREMENTIONED FILES, OR IF YOU DO */
- /* NOT HAVE THESE FILES, YOU SHOULD IMMEDIATELY CONTACT THE AUTHORS */
- /* AT THE ADDRESSES LISTED BELOW. IN NO EVENT SHOULD YOU PROCEED TO */
- /* USE THIS FILE WITHOUT HAVING ACCEPTED THE TERMS OF THE */
- /* BINKLEYTERM LICENSING AGREEMENT, OR SUCH OTHER AGREEMENT AS YOU */
- /* ARE ABLE TO REACH WITH THE AUTHORS. */
- /* */
- /* */
- /* The Authors can be reached at the following addresses: */
- /* */
- /* Robert C. Hartman Vincent E. Perriello */
- /* Spark Software VEP Software */
- /* 427-3 Amherst Street 111 Carroll Street */
- /* CS2032, Suite 232 Naugatuck, CT 06770 */
- /* Nashua, NH 03061 */
- /* */
- /* FidoNet 1:132/101 FidoNet 1:141/491 */
- /* Data (603) 888-8179 Data (203) 729-7569 */
- /* */
- /* Please feel free to contact us at any time to share your comments */
- /* about our software and/or licensing policies. */
- /* */
- /*--------------------------------------------------------------------------*/
-
- #include <dos.h>
- #include <time.h>
- #include <ctype.h>
- #include <stdio.h>
- #include <stdarg.h>
- #include <string.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <process.h>
- #include <io.h> /*PLF Fri 05-05-1989 08:54:00 */
- #include <stdlib.h> /*PLF Mon 05-08-1989 05:58:03 */
-
- #ifdef __TURBOC__
- #include <mem.h>
- #else
- #include <memory.h>
- #endif
-
- #include "com.h"
- #include "xfer.h"
- #include "zmodem.h"
- #include "keybd.h"
- #include "sbuf.h"
- #include "sched.h"
- #include "externs.h"
- #include "prototyp.h"
- #ifdef OS_2 /*PLF Fri 05-05-1989 07:24:36 */
- #define INCL_DOSFILEMGR
- #define INCL_DOSPROCESS
- #define INCL_VIO
- #include <os2.h>
- #endif
-
- static char newstring[100];
- static void fill_in_status (void);
-
-
- int dexists (filename)
- char *filename;
- {
- return(!access(filename, 0)); /*PLF Fri 05-05-1989 08:05:17 */
- }
-
- /*PLF Sat 05-06-1989 00:00:01
- * dfind() used to be here. It was replaced with the stuff in find.c
- *
- */
-
-
- int set_baud (baudrate, log)
- unsigned baudrate;
- int log;
- {
- register int i;
-
- if (!baudrate) /* "FAST" might do this */
- return (0);
-
- /* For 1200/75 split speed modems */
- if ((baudrate == 1275) || (baudrate == 7512))
- baudrate = 1200;
-
- if (max_baud && (baudrate > max_baud))
- baudrate = max_baud;
- else if (lock_baud)
- baudrate = max_baud;
-
- for (i = 0; btypes[i].str != NULL; i++)
- {
- if (atoi (btypes[i].str) == baudrate)
- {
- if (baud != i) /* same as what we have? */
- {
- if (log && !un_attended)
- status_line ("#Setting baud to %u", baudrate);
- baud = i; /* need this for ALT-B */
- cur_baud = baudrate; /*PLF Sat 05-06-1989 04:38:54 */
- MDM_ENABLE (btypes[baud].rate);
- }
- if (un_attended && fullscreen)
- {
- sb_move (settingswin, SET_PORT_ROW, SET_COL);
- sprintf (junk, "%-5u Com%d", baudrate, port_ptr + 1);
- sb_puts (settingswin, junk);
- sb_show ();
- }
- return (1);
- }
- }
- return (0);
- }
-
- static char *specifiers = "!*+:# ";
- static struct tm *tp;
- static time_t ltime;
- static char jbuf[20];
-
- void status_line (char *fmt,...)
- {
- va_list arg_ptr;
- /*PLF extern int errno; include stdlib.h instead. This fails in large/compact model */
-
- va_start (arg_ptr, fmt);
- errno = 0;
- vsprintf (e_input, fmt, arg_ptr);
- time (<ime);
- tp = localtime (<ime);
- if ((!fullscreen) || (!un_attended))
- {
- cprintf ("\r\n%c %02i %03s %02i:%02i:%02i BINK %s", e_input[0],
- tp->tm_mday, mtext[tp->tm_mon], tp->tm_hour, tp->tm_min, tp->tm_sec,
- &e_input[1]);
- }
- else
- {
- sprintf (stat_line, "%c %02i:%02i:%02i %-64.64s", e_input[0],
- tp->tm_hour, tp->tm_min, tp->tm_sec, &e_input[1]);
- fill_in_status ();
- }
- if ((status_log != NULL) &&
- ((strchr (specifiers, e_input[0]) - strchr (specifiers, '!')) <= loglevel))
- {
- fprintf (status_log, "%c %02i %03s %02i:%02i:%02i BINK %s\n", e_input[0],
- tp->tm_mday, mtext[tp->tm_mon], tp->tm_hour, tp->tm_min, tp->tm_sec,
- &e_input[1]);
- fflush (status_log);
- real_flush (fileno (status_log));
- }
-
- va_end (arg_ptr);
- }
-
- /*--------------------------------------------------------------------------*/
- /* THROUGHPUT */
- /* Print throughput message at end of transfer */
- /*--------------------------------------------------------------------------*/
- void throughput (opt, bytes)
- int opt;
- unsigned long bytes;
-
- {
- static byte *scrn = "+CPS: %lu (%lu bytes) Efficiency: %lu%%";
- static unsigned long started = 0L;
- static unsigned long elapsed;
- static unsigned long cps;
-
- if (!opt)
- started = time (NULL);
- else if (started)
- {
- elapsed = time (NULL) - started;
- if (elapsed == 0L)
- return;
- cps = bytes / elapsed;
- started = (cps * 1000L) / ((long) cur_baud);
- status_line (scrn, cps, bytes, started);
- }
- } /* throughput */
-
- static void fill_in_status ()
- {
-
- time (<ime);
- tp = localtime (<ime);
- if (fullscreen)
- {
- sb_scrl (callwin, 1);
- sb_move (callwin, CALL_STAT_ROW, 2);
- sb_puts (callwin, stat_line);
- sb_move (settingswin, SET_TIME_ROW, SET_TIME_COL);
- sprintf (junk, "%s %s %02d @ %02d:%02d",
- wkday[tp->tm_wday], mtext[tp->tm_mon], tp->tm_mday,
- tp->tm_hour, tp->tm_min);
- sb_puts (settingswin, junk);
- sb_show ();
- }
- }
-
- void clear_statusline ()
- {
- if (fullscreen)
- sb_fillc (callwin, ' ');
- }
-
- int got_error (string1, string2)
- char *string1, *string2;
- {
- /* extern int errno; */
-
- #ifdef __TURBOC__
- /* Since TurboC doesn't handle errno correctly, zero it and ignore. */
- errno = 0;
- #else
- if (errno == 0x18)
- errno = 0;
- if (errno != 0)
- {
- status_line ("!Error %d, Can't %s %s", errno, string1, string2);
- errno = 0;
- return (1);
- }
- #endif
- return (0);
- }
-
- void set_xy (string)
- char *string;
- {
- WRITE_ANSI ('\r');
- WRITE_ANSI ('\n');
- scr_printf (string);
- locate_x = wherex ();
- locate_y = wherey ();
- }
-
- void message (string)
- char *string;
- {
- if (string != NULL)
- {
- status_line (" %s", string);
- }
- }
-
- void time_release ()
- {
- #ifndef OS_2 /*PLF Fri 05-05-1989 07:06:27 */
- dos_break_off (); /* Turn off ^C trapping */
-
- if (have_dv)
- {
- dv_pause ();
- }
- else if (have_ddos)
- {
- ddos_pause ();
- }
- else if (have_tv)
- {
- tv_pause ();
- }
- else if (have_ml)
- {
- ml_pause ();
- }
- #else /*PLF Fri 05-05-1989 07:06:44 */
-
- /* OS/2 notes. I take it this function will be called when we want to
- * give up the rest of the current time slice. I have interpreted this to
- * be DosSleep(1L) for Binkley Term in os/2. Perhaps you may think it
- * should be DosSleep(0L). I include the following to help you decide:
- */
-
- /*
- * The DosSleep function causes the current thread to wait for a
- * specified interval of time or, if the requested interval is zero, to
- * give up the remainder of the current time slice. The actual time the
- * thread waits can be off by a clock tick or two, depending on the
- * execution status of the other threads running in the system. If the
- * specified time interval is zero, the process will forego the
- * remainder of its CPU time slice but will be scheduled normally for
- * its next time slice. Otherwise, the time is given in milliseconds,
- * rounded up to the resolution of the scheduler clock.
- *
- * The DosSleep function is a family API function.
- *
- * Comments
- *
- * For short time intervals, the rounding-up process combined with the
- * thread-priority interactions can cause the waiting interval to be
- * longer than the requested time. Also, when a process continues after
- * suspension, it is scheduled for execution, although that execution
- * could be delayed by hardware interrupts or by another thread running
- * at a higher priority. In no case should the DosSleep function be
- * substituted for a real-time clock because the rounding of the sleep
- * interval will cause accumulative errors.
- */
-
- DosSleep(1L);
-
- #endif /*PLF Fri 05-05-1989 07:06:52 */
- }
-
- void adios (n)
- int n;
- {
- if (vfossil_installed)
- vfossil_close ();
-
- MDM_DISABLE ();
- exit (n);
- }
-
- char *fancy_str (string)
- char *string;
- {
- register int flag = 0;
- char *s;
-
- s = string;
-
- while (*string)
- {
- if (isalpha (*string)) /* If alphabetic, */
- {
- if (flag) /* already saw one? */
- *string = tolower (*string); /* Yes, lowercase it */
- else
- {
- flag = 1; /* first one, flag it */
- *string = toupper (*string); /* Uppercase it */
- }
- }
- else /* if not alphabetic */ flag = 0; /* reset alpha flag */
- string++;
- }
-
- return (s);
- }
-
- void timer (interval)
- int interval;
- {
- long timeout, timerset ();
-
- timeout = timerset (interval * 10);
- while (!timeup (timeout))
- time_release ();
- }
-
- void big_pause (secs)
- int secs;
- {
- long timeout, timerset ();
-
- timeout = timerset (secs * 100);
- while (!timeup (timeout))
- {
- if (CHAR_AVAIL ())
- break;
- time_release ();
- }
- }
-
- unsigned int com_getc (t)
- int t;
- {
- unsigned char c;
- long t1;
- extern long timerset ();
-
- if (CHAR_AVAIL ())
- {
- c = (char) (MODEM_IN () & 0xff);
- }
- else
- {
- t1 = timerset (t * 100);
- while (!CHAR_AVAIL ())
- {
- if (timeup (t1))
- {
- return (EOF);
- }
-
- /*
- * This should work because we only do TIMED_READ when we have
- * carrier
- */
- if (!CARRIER)
- {
- return (EOF);
- }
- time_release ();
- }
- c = (char) (MODEM_IN () & 0xff);
- }
- return (c);
- }
-
- /* Z F R E E -- Return total number of free bytes on drive specified */
- #ifndef OS_2 /*PLF Fri 05-05-1989 07:14:36 */
- long zfree (drive)
- char *drive;
- {
- union REGS r;
-
- unsigned char driveno;
- long stat;
-
- if (drive[0] != '\0' && drive[1] == ':')
- {
- driveno = islower (*drive) ? toupper (*drive) : *drive;
- driveno = driveno - 'A' + 1;
- }
- else driveno = 0; /* Default drive */
-
- r.x.ax = 0x3600; /* get free space */
- r.h.dl = driveno; /* on this drive */
- int86 (0x21, &r, &r); /* go do it */
-
- if (r.x.ax == 0xffff) /* error return?? */
- return (0);
-
- stat = (long) r.x.bx /* bx = clusters avail */
- * (long) r.x.ax /* ax = sectors/clust */
- * (long) r.x.cx; /* cx = bytes/sector */
-
- return (stat);
- }
- #else /*PLF Fri 05-05-1989 07:14:36 */
- long zfree(char *path)
- {
- int drive;
- FSALLOCATE dt;
-
- if(!path || !*path)
- drive = 0;
- else
- drive = tolower(*path) - 'a' + 1;
- DosQFSInfo(drive,1, (char far *) &dt, sizeof(FSALLOCATE));
- return( dt.cSectorUnit *
- dt.cUnitAvail *
- dt.cbSector );
- }
- #endif /*PLF Fri 05-05-1989 07:14:36 */
-
- void scr_printf (string)
- char *string;
- {
- if (string != NULL)
- #ifdef OS_2 /*PLF Fri 05-05-1989 07:17:59 */
- /* This may have to be either VioWrtTTY() or VioWrtTTy()
- * depending on which version of the
- * bse*.h files you have for os/2
- */
- (void) VioWrtTTY(string, (USHORT) strlen(string), (HVIO) 0L);
- #else
- while (*string != 0)
- WRITE_ANSI (*string++);
- #endif
- }
-
- void send_can ()
- {
- int i;
- #ifdef OS_2 /*PLF Sat 05-06-1989 09:11:09 */
- CLEAR_OUTBOUND();
- CLEAR_INBOUND();
- #endif
-
- for (i = 0; i < 10; i++)
- SENDBYTE (CAN);
- for (i = 0; i < 10; i++)
- SENDBYTE (BS);
- }
-
- void invent_pkt_name (string)
- char string[];
-
- {
- struct tm *tp;
- time_t ltime;
-
- time (<ime);
- tp = localtime (<ime);
- sprintf (string, "%02i%02i%02i%02i.pkt",
- tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec);
- }
-
- static char *suffixes[8] = {
- "SU", "MO", "TU", "WE", "TH", "FR", "SA", NULL
- };
-
- int is_arcmail (p, n)
- char *p;
- int n;
- {
- int i;
- char c[128];
-
- if (!isdigit (p[n]))
- {
- return (0);
- }
-
- strcpy (c, p);
- strupr (c);
-
- for (i = n - 11; i < n - 3; i++)
- {
- if ((!isdigit (c[i])) && ((c[i] > 'F') || (c[i] < 'A')))
- return (0);
- }
-
- for (i = 0; i < 7; i++)
- {
- if (strnicmp (&c[n - 2], suffixes[i], 2) == 0)
- break;
- }
-
- if (i >= 7)
- {
- return (0);
- }
-
- got_arcmail = 1;
- return (1);
- }
-
- int get_number (target)
- char *target;
- {
- int zone, net, node, point;
- int k;
-
- fgets (target, 100, stdin);
- k = strlen (target);
- if (k == 1)
- return (0);
- target[--k] = '\0'; /* no '\n' */
- if (!isdigit (target[0]) && target[0] != '\"')
- {
- fidouser (target, &zone, &net, &node, &point);
- if ((net != -1) && (node != -1) && (zone != -1))
- {
- if (zone == alias[0].Zone)
- sprintf (target, "%d/%d", net, node);
- else sprintf (target, "%d:%d/%d", zone, net, node);
- }
- else return (0); /* Gotta have addr */
- }
- return (1);
- }
-
- void gong ()
- {
- long t, timerset ();
- int i;
-
- if (!gong_allowed)
- return;
-
- for (i = 0; i < 15; i++)
- {
- WRITE_ANSI ('\07'); /* Bell code */
- t = timerset (100); /* 1 second */
- while (!timeup (t))
- {
- if (KEYPRESS ()) /* If key pressed, */
- {
- READKB (); /* Throw it away */
- return; /* And get out */
- }
- }
- }
- }
-
- char *skip_blanks (string)
- char *string;
- {
- while (*string && isspace (*string))
- ++string;
- return (string);
- }
-
- char *skip_to_blank (string)
- char *string;
- {
- while (*string && (!isspace (*string)))
- ++string;
- return (string);
- }
-
- #ifdef DEBUG
- void show_debug_name (string)
- char *string;
- {
- int x, y;
- static char *filler = " ";
-
- x = wherex ();
- y = wherey ();
- gotoxy (40, 0);
- scr_printf (string);
- scr_printf (&filler[strlen (string)]);
- gotoxy (x, y);
- }
- #endif
-
- int parse (input, list)
- char *input;
- struct parse_list list[];
-
- {
- int i;
-
- for (i = 0; list[i].p_length; i++)
- {
- if (strnicmp (input, list[i].p_string, list[i].p_length) == 0)
- return (++i);
- }
- return (-1);
- }
-
- void change_prompt ()
- {
- char *s;
-
- if (newstring[0])
- {
- putenv (newstring);
- return;
- }
-
- strcpy (newstring, "PROMPT=[");
- strcat (newstring, xfer_id);
- #ifdef OVERLAYS
- strcat (newstring, "-Overlay");
- #endif
- strcat (newstring, " Shell]$_");
- s = getenv ("PROMPT");
- if (s)
- {
- strcat (newstring, s);
- }
- else
- {
- strcat (newstring, "$P$G");
- }
-
- putenv (newstring);
- }
-
- void update_files (t)
- int t;
- {
- char s[10];
-
- if (un_attended && fullscreen)
- {
- if (t)
- {
- ++hist.files_out;
- }
- else
- {
- ++hist.files_in;
- }
-
- sb_move (historywin, HIST_FILE_ROW, HIST_COL);
- sprintf (s, "%d/%d", hist.files_in, hist.files_out);
- sb_puts (historywin, s);
- sb_show ();
- }
- }
-
- static char *last_str[] = {
- " None ",
- " WaZOO ",
- " FSC-0001",
- " BBS ",
- " Ext Mail"
- };
-
- void last_type (n, zone, net, node)
- int n;
- int zone;
- int net;
- int node;
- {
- int i;
- char j[20];
-
- if (fullscreen)
- sb_move (historywin, HIST_LAST_ROW, HIST_COL2);
-
- if ((n == 1) || (n == 2))
- {
- if ((zone != -1000) && (net > 0))
- {
- sprintf (j, "%d:%d/%d", zone, net, node);
- for (i = strlen (j); i < 13; i++)
- j[i] = ' ';
- j[i] = '\0';
- hist.last_zone = zone;
- hist.last_net = net;
- hist.last_node = node;
- }
- else
- {
- strcpy (j, " FSC-0001");
- }
- if (fullscreen)
- sb_puts (historywin, j);
- }
- else
- {
- if ((n < 0) || (n > 4))
- n = 0;
-
- if (fullscreen)
- sb_puts (historywin, last_str[n]);
- }
-
- hist.last_caller = n;
- }
-
-
- /*--------------------------------------------------------------------------*/
- /* CHECK_NETFILE -- find out if the file we've got is a netfile. */
- /*--------------------------------------------------------------------------*/
-
- char *check_netfile (fname)
- char *fname;
- {
- register byte *p;
- register int n;
-
- p = fname;
- n = strlen (p) - 1;
-
- if ((p[n] == 't') && (p[n - 1] == 'k') && (p[n - 2] == 'p') && (p[n - 3] == '.'))
- {
- got_packet = 1;
- got_mail = 1;
- p = "Mail Packet ";
- }
- else if (is_arcmail (p, n))
- {
- got_mail = 1;
- p = "Compressed Mail ";
- }
- else
- {
- /* Don't set 'got_mail' if it's a .REQ file */
- if ((p[n] != 'q') || (p[n - 1] != 'e') || (p[n - 2] != 'r') || (p[n - 3] != '.'))
- got_mail = 1;
- p = "Net File ";
- }
-
- return (p);
- }
-
- /*--------------------------------------------------------------------------*/
- /* UNIQUE_NAME */
- /* Increments the suffix of a filename as necessary to make the name unique */
- /*--------------------------------------------------------------------------*/
- void unique_name (fname)
- char *fname;
- {
- static byte suffix[] = ".001";
- register char *p;
- register int n;
-
- if (dexists (fname))
- { /* If file already exists... */
- p = fname;
- while (*p && *p != '.')
- p++; /* ...find the extension, if
- * any */
- for (n = 0; n < 4; n++) /* ...fill it out if
- * neccessary */
- if (!*p)
- {
- *p = suffix[n];
- *(++p) = '\0';
- }
- else p++;
-
- while (dexists (fname)) /* ...If 'file.ext' exists
- * suffix++ */
- {
- p = fname + strlen (fname) - 1;
- for (n = 3; n--;)
- {
- if (!isdigit (*p))
- *p = '0';
- if (++(*p) <= '9')
- break;
- else *p-- = '0';
- } /* for */
- } /* while */
- } /* if exist */
- } /* unique_name */
-
- int got_ESC ()
- {
- if (((KEYPRESS ()) && (READKB () == 27))) /* ESC pressed? */
- {
- while (KEYPRESS ())
- READKB ();
- return (1);
- }
- return (0);
- }